package com.wsoft.mq.test.sample.headers;

import com.rabbitmq.client.Channel;
import com.wsoft.mq.test.constant.RabbitHeadersConstant;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author z001
 * @Date 2025/1/7 15:40
 */
@Component
public class HeadersReceiveSample {


    @RabbitListener(queues = RabbitHeadersConstant.HEADERS_QUEUE_1)
    public void listener1(Message message, String content, Channel channel,
                         @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        System.out.println("headers1-收到信息1,message:" + content);
    }

    @RabbitListener(queues = RabbitHeadersConstant.HEADERS_QUEUE_2)
    public void listener2(Message message, String content, Channel channel,
                         @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException {
        System.out.println("headers2-收到信息2,message:" + content);
    }

}
